package com.yy.wga.mp.module.resource.controller;

import com.yy.wga.common.core.dto.Result;
import com.yy.wga.common.utils.mapping.BeansUtils;
import com.yy.wga.mp.module.resource.request.ListResourceRequest;
import com.yy.wga.mp.module.resource.response.ListResourceResponse;
import com.yy.wga.resource.feign.api.ResourceConfigFeign;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 资源位配置
 *
 * @author guochao
 * @since 2024-10-31 22:48:51
 */
@RestController
@RequestMapping("api/resource/config")
public class ResourceConfigController {
    /**
     * 服务对象
     */
    @Resource
    private ResourceConfigFeign resourceConfigFeign;

    /**
     * 获取资源位信息
     * @param request
     * @return
     */
    @PostMapping("list")
    public Result<List<ListResourceResponse>> list(@Validated @RequestBody ListResourceRequest request) {
        com.yy.wga.resource.feign.request.ListResourceRequest listResourceRequest = BeansUtils.map(request, com.yy.wga.resource.feign.request.ListResourceRequest.class);
        Result<List<com.yy.wga.resource.feign.response.ListResourceResponse>> result = resourceConfigFeign.list(listResourceRequest);
        if (result.isSuccess()) {
            List<com.yy.wga.resource.feign.response.ListResourceResponse> data = result.getData();
            List<ListResourceResponse> listResourceResponseList = BeansUtils.mapList(data, ListResourceResponse.class);
            return Result.success(listResourceResponseList);
        }
        return Result.fail(result.getCode(), result.getMessage());
    }
}
